//
//  WBMianViewController.swift
//  weibo
//
//  Created by 胡古古 on 2017/6/4.
//  Copyright © 2017年 hugugu. All rights reserved.
//

import UIKit
import SVProgressHUD

class WBMianViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let tabBar = WBTabBar()
        // 回调闭包
        tabBar.composeCallBack = {
            
            if !WBUserAccountViewModel.sharedViewModel.isLogin {
                SVProgressHUD.showInfo(withStatus: "请先登录, 亲~")
                
                return
            }
            
            let composeView = WBComposeView()
            
            composeView.show(target: self)
        }
        
        setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(childController: WBHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(childController: WBMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(childController: WBDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(childController: WBMeTableViewController(), title: "我的", imageName: "tabbar_profile")
    }

     func addChildViewController(childController: UIViewController,title:String,imageName:String) {
        // 设置标签图片
        childController.tabBarItem.image = UIImage(named: imageName)
        // 设置标签的选中图片
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.withRenderingMode(.alwaysOriginal)
        // 设置文字的颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)
        // 设置文字的大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 13)], for: .normal)
        // 设置导航控制器
        let nav = WBNavigationViewController(rootViewController: childController)
        // 设置名字
        childController.title = title
        // 添加导航控制器
        addChildViewController(nav)
        
    }
}
